import type { PostLoginData } from "@/types/common";
import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserStore =  defineStore("user", () => {
  const token = ref('')
  const setToken = (val: string) => {
    token.value = val
  }
  const clearToken = () => {
    token.value = ''
  }
  // 获取用户信息
  const userInfo = ref<PostLoginData>()
  const setUserInfo = (value: PostLoginData) => {
    userInfo.value = value
  }

  const clearUserInfo = () => {
    userInfo.value = undefined
  }
  return { token, setToken, clearToken, userInfo, setUserInfo, clearUserInfo }
},
// 持久化
{persist: true}
)